package com.cdy.jxc_project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cdy.jxc_project.domain.TSupplier;
import com.cdy.jxc_project.domain.vo.TSupplierVo;
import com.cdy.jxc_project.json.R;
import com.cdy.jxc_project.service.TSupplierService;
import com.cdy.jxc_project.utils.AddSysLog;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/*
 * @Project:jxc_project
 * @Author:cdy(缘生)
 * @Motto:放下杂念,只为迎接明天更好的自己
 * @Date:2023/4/21 18:32
 * */
@RestController
@RequestMapping("/tSupplier")
public class TSupplierController {

    @Resource
    private TSupplierService tSupplierService;
    @AddSysLog
    @PostMapping("/queryAll")
    public R tSupplierList(@RequestBody TSupplierVo tSupplierVo){
        Page<TSupplier> tSupplierPage = tSupplierService.queryTSupplierPage(tSupplierVo);
        return R.ok().message("查询成功").data("tSupplierList",tSupplierPage);
    }
    @AddSysLog
    @DeleteMapping("/deleteTSupplier/{id}")
    public R deleteTSupplier(@PathVariable Integer id){
        tSupplierService.deleteTSupplier(id);
        return R.ok().message("删除成功");
    }
    @AddSysLog
    @PostMapping("/insertAndUpdateTSupplier")
    public R insertAndUpdateTSupplier(@RequestBody TSupplier tSupplier){
        try{
            if (tSupplier.getId()==null){
                tSupplierService.insertTSupplier(tSupplier);
                return R.ok().message("保存成功");
            }else {
                tSupplierService.updateTSupplier(tSupplier);
                return R.ok().message("修改成功");
            }

        }catch (Exception e){
            e.printStackTrace();
            return R.error().message("程序出错");
        }
    }

}
